package t_257

import "strconv"

var ans []string

func binaryTreePaths(root *TreeNode) []string {
	ans = []string{}
	if root == nil {
		return ans
	}
	dfs(root, "")
	return ans
}

func dfs(root *TreeNode, path string) {
	if root == nil {
		return
	}
	if root.Left == nil && root.Right == nil {
		ans = append(ans, path+strconv.Itoa(root.Val))
		return
	}

	dfs(root.Left, path+strconv.Itoa(root.Val)+"->")
	dfs(root.Right, path+strconv.Itoa(root.Val)+"->")
	return
}

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}
